#include "StdAfx.h"
#include <cassert>
#include "AdderBytecodeEngine.h"
#include "AdderBuiltinFunction.h"

BuiltinFunction::BuiltinFunction()
{
	// Our builtin was initalized incorrectly.
	assert(false);
}

BuiltinFunction::BuiltinFunction(BuiltinFunction0 func)
{
	this->func0 = func;
	this->argument_count = 0;
	this->isBuiltin = true;
}

BuiltinFunction::BuiltinFunction(BuiltinFunction1 func)
{
	this->func1 = func;
	this->argument_count = 1;
	this->isBuiltin = true;
}

BuiltinFunction::BuiltinFunction(BuiltinFunction2 func)
{
	this->func2 = func;
	this->argument_count = 2;
	this->isBuiltin = true;
}

BuiltinFunction::BuiltinFunction(BuiltinFunction3 func)
{
	this->func3 = func;
	this->argument_count = 3;
	this->isBuiltin = true;
}

BuiltinFunction::BuiltinFunction(BuiltinFunction4 func)
{
	this->func4 = func;
	this->argument_count = 4;
	this->isBuiltin = true;
}

BuiltinFunction::BuiltinFunction(BuiltinFunction5 func)
{
	this->func5 = func;
	this->argument_count = 5;
	this->isBuiltin = true;
}

AdderValue * BuiltinFunction::execute(AdderBytecodeEngine* engine)
{
	assert(this->argument_count == 0);
	return this->func0(engine);
}

AdderValue * BuiltinFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1)
{
	assert(this->argument_count == 1);
	return this->func1(engine, arg1);
}

AdderValue * BuiltinFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1, AdderValue* arg2)
{
	assert(this->argument_count == 2);
	return this->func2(engine, arg1, arg2);
}

AdderValue * BuiltinFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1, AdderValue* arg2, AdderValue* arg3)
{
	assert(this->argument_count == 3);
	return this->func3(engine, arg1, arg2, arg3);
}

AdderValue * BuiltinFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1, AdderValue* arg2, AdderValue* arg3, AdderValue* arg4)
{
	assert(this->argument_count == 4);
	return this->func4(engine, arg1, arg2, arg3, arg4);
}

AdderValue * BuiltinFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1, AdderValue* arg2, AdderValue* arg3, AdderValue* arg4, AdderValue* arg5)
{
	assert(this->argument_count == 5);
	return this->func5(engine, arg1, arg2, arg3, arg4, arg5);
}